import Vue from 'vue'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets

import ElementUI from 'element-ui'
import pageTools from '@/components/PageTools'
import upload from '@/components/uploadimg/index.vue'
import ImageHolder from '@/components/ImageHolder'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/en' // lang i18n

import '@/styles/index.scss' // global css

import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control

// 注册全局自定义指令
Vue.directive('allow', {
  inserted: (el, binding) => {
    // 从vuex中取出points,
    const points = store.state.user.userInfo.roles.points
    // 如果绑定的元素的binding-value有points中的值则显示
    if (points.includes(binding.value)) {
      // show el
    } else {
      // remove el
      el.parentNode.removeChild(el)
    }
  }
})
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

// set ElementUI lang to EN
Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

// 注册全局组件
Vue.component('pageTool', pageTools)
Vue.component('upload', upload)
Vue.component('ImageHolder', ImageHolder)

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
